home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / wstr.exe / WSTR.DOC < prev    next >
Text File  |  1993-02-12  |  44KB  |  1,089 lines

  1. Wheaton Strings library documentation
  2.  
  3. October 10, 1989
  4. February 20, 1991 (minor update)
  5. May 15, 1992 (minor update)
  6. October 20, 1992 (minor update)
  7. January 27, 1993 (add String40 and String120 - fix some documentation bugs)
  8.  
  9. Copyright (c) 1992, 1993 by Paul Wheaton
  10.  
  11. Note that this documentation does not cover all of the features of the
  12. provided in this library.  For that, you will have to look at the header files.
  13.  
  14. The Wheaton Libraries are shareware. Anyone may use the libraries provided
  15. that they do not change them.  If you want to change them or if you want
  16. phone support from me, you must pay $50. This in the hope that the hundreds
  17. of vendors that are creating their own string libraries can go with just
  18. one - I'm pretty tired of getting a library in that seems like it will be
  19. pretty cool, just to find out that it uses the same identifiers as
  20. something else and there are then link conflicts.
  21.  
  22. For those programmers that never read documentation but have
  23. mysteriously made it this far, just look quickly at section 1.1.4 and
  24. 5.1.  To make these libraries available, you need to include
  25. <Strings.h> link with WLIB.LIB and FATAL.OBJ (or WW.LIB which includes
  26. a different FATAL.OBJ).
  27.  
  28. This Strings library, consisting of one class and a few independent
  29. functions, provides an easier, more intuitive way to manipulate
  30. strings.  By including this stuff into your programs you can use (or
  31. create!) functions that do not need chunks of memory pre-allocated for
  32. them.  Concatenation is done with "+" or "+=" instead of "strcat".
  33. Comparison is done with "==", "!=", "<", etc. instead of "strcmp".
  34. Source ends up being more readable, and less verbose.  Many common
  35. string manipulation errors are completely eliminated.  For programmers
  36. new to "C", these libraries provide more functionality with fewer
  37. operators to memorize, thus reducing the dreaded learning curve.
  38.  
  39. (note - there is now more than one class, but you may treat the class
  40. "String" as if it were just one.  Later, when you have more experience, you
  41. can use the classes String40 and String120 for optimization)
  42.  
  43. Strings are automatically converted from type String to char* and back
  44. as needed.  The two types can often be mixed to give the same results.
  45.  
  46.  
  47.       Strings
  48. 1       Advantages over C
  49. 1.1       for programmers new to C
  50. 1.1.1       less to memorize
  51. 1.1.2       more intuitive
  52. 1.1.3       similar to other languages
  53. 1.1.4       faster to learn
  54. 1.2       for old C programmers
  55. 1.2.1       less to type
  56. 1.2.2       less worry about low level stuff: concentrate more on program
  57. 1.2.3       more readable
  58. 1.2.4       eliminate overflow errors
  59. 1.2.5       faster executable
  60.               length does not need to be calculated
  61. 1.2.6       use less memory
  62.               don't need to allocate memory to cover "worst case"
  63. 1.2.7       functions that are more independent (don't need storage space)
  64. 2       Disadvantages from C
  65. 2.1       speed overhead
  66.             allocating memory in the heap at creation and appending
  67. 2.2       storage overhead
  68.             storing length and extra pointers
  69. 3       A little bit about how this works
  70. 4       Implementing this with char* for optimal performance
  71. 5       Functions
  72. 5.1       String class member functions
  73. 5.1.1       declaring a String
  74. 5.1.1.1       based on a given string constant or char*
  75. 5.1.1.2       based on a character
  76. 5.1.1.3       based on another String
  77. 5.1.1.4       without initialization
  78. 5.1.1.5       extra allocation
  79. 5.1.2       Length() or Size()
  80. 5.1.3       + (concatenation)
  81. 5.1.4       += (appending form of concatenation)
  82. 5.1.5       = (assignment) and conversions
  83. 5.1.6       ==,!=,<,>,<=,>= (comparison)
  84. 5.1.7       () or At() (retrieving substrings)
  85. 5.1.7.1       Before(), Through(), From() and After()
  86. 5.1.8       [] (String char reference)
  87. 5.1.9       Left(), Right(), Center(), Just()  (justification)
  88. 5.1.10      Capacity() (report current allocation)
  89. 5.1.11      ReAlloc() (change capacity)
  90. 5.1.12      ToLower() (force all upper case letters to lower case)
  91. 5.1.13      ToUpper() (force all lower case letters to upper case)
  92. 5.1.14      Index() (find the index of a char)
  93. 5.1.15      Insert() (insert a char or a sting into the string)
  94. 5.1.16      Delete() (delete characters from the string)
  95. 5.2       non-member functions
  96. 5.2.1       Str() (convert integers to String)
  97. 5.2.2       Form() (convert reals to a String using a format)
  98. 5.2.3       StringOf() (return a string of chars)
  99. 5.2.4       Spaces() (return a String of a certain number of spaces)
  100. 5.2.5       LeftText(), RightText(), CenterText(), JustText()
  101.  
  102.  
  103.  
  104. 1 Advantages over C
  105.  
  106.   I hope to show that using these String libraries in C++ is a great deal
  107.   easier than using the ANSI C string libraries or any string library that
  108.   could possibly be written in C.  It is my opinion that productivity in
  109.   string manipulation development will increase by a factor of four for
  110.   those application programmers that use this library.
  111.  
  112. 1.1 for programmers new to C
  113.  
  114.   Any time that you move to a new language there will be a learning curve.
  115.   C is notorious for being too terse and, thus, hard to read and tougher to
  116.   learn.  Much of this has to do with being a "mid level language":  Easier
  117.   to work with than assembly yet harder than "high level languages" such as
  118.   Pascal or FORTRAN.  C gains you a great deal of portability and runtime
  119.   effeciency over most "high level languages".  C++ with a healthy set of
  120.   libraries provides all of the advantages of C coupled with the advantages
  121.   of a high level language.  This library should make string manipulation
  122.   easier than not only C, but FORTRAN, Pascal, BASIC, LISP or Modula-2.  A
  123.   programmer new to this library will probably find all of the string
  124.   manipulation features that they appreciated most in their favorite
  125.   languages and then some new twists that will make their programming lives
  126.   even easier.
  127.  
  128. 1.1.1 less to memorize
  129.  
  130.   C++ cures some of the idiosyncrasies of C that directly effect
  131.   string manipulation libraries, one of the worst being the pointer to
  132.   a character concept.  In order for a programmer to keep from getting
  133.   into trouble when manipulating strings in C, they must memorize how
  134.   the compiler handles them (the strings):  C Strings are an array of
  135.   characters terminated by a null character; strings are referenced by
  136.   a pointer to the first element of the string; runtime range checking
  137.   is not standard and is performed with library routines when the size
  138.   of the string is passed.
  139.  
  140.   In this library, how the String is actually stored and manipulated
  141.   is hidden from the applications programmer.  Runtime range checking
  142.   is performed by the library so the applications programmer can
  143.   concentrate on their application rather than monitor the size of
  144.   their strings and make sure everything will fit.  Since string
  145.   manipulation using this library is similar to working with numbers
  146.   in C or C++, all of the exceptions for plain C string handling never
  147.   have to be learned.
  148.  
  149. 1.1.2 more intuitive
  150.  
  151.   ANSI C maintains a great deal of exceptions when it comes to string
  152.   handling.  For example, if you have two strings, S1 and S2,
  153.   assignment of one from the other does not result in two identical
  154.   copies of the string, it results in two pointers pointing to the
  155.   same string:  Modifying one effects the other.  Generally, when an
  156.   assignment is made such as X=Y, the contents of X are separate from
  157.   Y yet the same.  This library supports the more intuitive assignment
  158.   operation as well as other operators and functions that any string
  159.   library *ought* to have.
  160.  
  161. 1.1.3 similar to other languages
  162.  
  163.   Of course, all of the functions and operators available in C are
  164.   also available in C++.  Many of them (C functions) will work with
  165.   the String type as well as good ole char*.
  166.  
  167.   In Turbo Pascal
  168.  
  169.     Var S1,S2:String;
  170.     Begin
  171.       S1:="oatmeal";
  172.       S2:="I like "+S1+".";
  173.     End;
  174.  
  175.   In BASIC
  176.  
  177.     550 S1$="oatmeal"
  178.     560 S2$="I like "+S1$+"."
  179.  
  180.   In FORTRAN
  181.  
  182.     char S1*8
  183.     char S